package com.wanlian.router.ui.main.yun;

import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wanlian.router.R;
import com.wanlian.router.bean.YunPictureGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Hyu on 2018/9/3.
 * Email: fvaryu@qq.com
 */
public class YunPictureAdapter extends RecyclerView.Adapter<YunPictureAdapter.YunPictureHolder>{
    private List<YunPictureGroup> mYunPictureGroups;

    public YunPictureAdapter(List<YunPictureGroup> yunPictureGroups) {
        mYunPictureGroups = yunPictureGroups;
    }

    @NonNull
    @Override
    public YunPictureHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new YunPictureHolder(LayoutInflater.from(viewGroup.getContext())
        .inflate(R.layout.layout_item_yun_picture, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull YunPictureHolder yunPictureHolder, int i) {
        YunPictureGroup yunPictureGroup = mYunPictureGroups.get(i);
        yunPictureHolder.tv_time.setText(yunPictureGroup.getTime());
        yunPictureHolder.mRecyclerView.setAdapter(new PhotoAdapter(yunPictureGroup.getItems()));
    }

    @Override
    public int getItemCount() {
        return mYunPictureGroups.size();
    }

    class YunPictureHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.recycler_view)
        RecyclerView mRecyclerView;
        @BindView(R.id.tv_time)
        TextView tv_time;
        public YunPictureHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
                @Override
                public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
                    outRect.set(0, itemPosition / 5 > 0 ? 15 : 0, 0, 0);
                }
            });
        }
    }
}
